//
//  DWDSearchView.swift
//  dwdWb
//
//  Created by Dengdwd on 15/10/9.
//  Copyright © 2015年 dwd. All rights reserved.
//

import UIKit

class DWDSearchView: UIView,UITextFieldDelegate {

    @IBOutlet weak var textFieldTrallingCons: NSLayoutConstraint!
    @IBOutlet weak var cancleBtn: UIButton!
    @IBOutlet weak var textField: UITextField!
    class func loadSearchView()->DWDSearchView{
        return NSBundle.mainBundle().loadNibNamed("DWDSearchView", owner: nil, options: nil).last as! DWDSearchView
    }
    override func awakeFromNib() {
        textField.delegate = self
        
        let leftView = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
        leftView.bounds.size = CGSize(width: h, height: h)
        leftView.contentMode = UIViewContentMode.Center
        textField.leftView = leftView
        textField.leftViewMode = UITextFieldViewMode.Always
    }
    func textFieldDidBeginEditing(textField: UITextField) {
        textFieldTrallingCons.constant = 45
        UIView .animateWithDuration(0.25, animations: { () -> Void in
            self.layoutIfNeeded()
        })
    }
    func textFieldDidEndEditing(textField: UITextField) {
        textFieldTrallingCons.constant = 0
        UIView .animateWithDuration(0.25, animations: { () -> Void in
            self.layoutIfNeeded()
        })
    }
    @IBAction func cancle(sender: AnyObject) {
        self.endEditing(true)
    }
}
